package org.crazyit.activiti_d2._4_NoGenDiagram;

import org.activiti.engine.ProcessEngine;
import org.activiti.engine.ProcessEngineConfiguration;
import org.activiti.engine.ProcessEngines;
import org.activiti.engine.RepositoryService;
import org.activiti.engine.repository.Deployment;
import org.activiti.engine.repository.ProcessDefinition;

public class NoGenDiagram {

    public static void main(String[] args) {

        //1. 创建流程引擎
        ProcessEngine engine = ProcessEngines.getDefaultProcessEngine();

        //2. 得到流程存储服务实例
        RepositoryService repositoryService = engine.getRepositoryService();

        //3. 部署流程描述文件与流程图
        Deployment deploy = repositoryService.createDeployment().addClasspathResource("noGenDiagram.bpmn").deploy();

        //4. 查询流程定义实体
        ProcessDefinition processDefinition = repositoryService.createProcessDefinitionQuery().deploymentId(deploy.getId()).singleResult();

        //5. 输出结果为diagram.vacationProcess.png
        System.out.println(processDefinition.getDiagramResourceName());

        //6. 读取不生成流程图的配置文件
        ProcessEngineConfiguration noConfig = ProcessEngineConfiguration.createProcessEngineConfigurationFromResource("noGenDiagram.cfg.xml");
        ProcessEngine noGenEngine = noConfig.buildProcessEngine();
        RepositoryService noGenService = noGenEngine.getRepositoryService();
        Deployment noGenDep = noGenService.createDeployment().addClasspathResource("noGenDiagram.bpmn").deploy();
        ProcessDefinition noGenDef = noGenService.createProcessDefinitionQuery().deploymentId(noGenDep.getId()).singleResult();

        //7. 输出不生成流程图的流程实例资源名
        System.out.println(noGenDef.getDiagramResourceName());

    }

}
